package com.yinian.cart.service.ProductList;


import com.yinian.cart.entity.ProductList;
import com.yinian.cart.repository.ProductListRepository;
import jakarta.transaction.Transactional;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Transactional
public class ProductListServiceImpl implements ProductListService{
    @Autowired
    private ProductListRepository productListRepository;
    @Override
    public JSONArray findAllProductList() {
        List<ProductList> productListList = productListRepository.findAll();
        JSONArray jsonArray = new JSONArray();
        for(ProductList productList : productListList){
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("productId",productList.getProductId());
            jsonObject.put("productName",productList.getProductName());
            jsonObject.put("productIntroduce",productList.getProductIntroduce());
            jsonObject.put("productPic",productList.getProductPic());
            jsonObject.put("productPrice",productList.getProductPrice());
            jsonArray.put(jsonObject);
        }
        return jsonArray;
    }
}
